var {
    lsGetObj
} = require('./request');
/**
 *操作成功提示
 */
exports.fnSuccess = function (msg) {
    wx.showToast({
        title: msg || '操作成功！',
        mask: true,
    })
}
exports.setTitle=function(title){
  wx.setNavigationBarTitle({
    title: title|| '标题',
  })
}
/**
 *操作成功提示
 */
exports.fnFail = function (content) {
    wx.showModal({
        title: '提示',
        content: content || '操作失败',
        mask: true,
        showCancel: false
    })
}
/**
 * 打开加载框
 */
exports.fnLoading = function (tips) {
    wx.showLoading({
        title: tips || '加载中...',
        mask: true,
    })
}
/**
 * 关闭加载框
 */
exports.fnHideLoading = function () {
    wx.hideLoading();
}

/**
 * 获取登录用户信息对象
 */
exports.getLoginedUser = function () {

    return new Promise(function (resolve, reject) {
        let user = lsGetObj('loginedUser');
        //debugger;
        if (Object.keys(user).length == 0) {
            console.log('请授权登录～！')
            return reject('未登录');
        }
        return resolve(user || {});
    })

}

// exports.formatDate = function () {
//     return new Promise(function (resolve, reject) {
//         return resolve(lsGetObj('loginedUser') || {});
//     })
// }

exports.formatDate = function (data) {
    var date = new Date(data || Date.now());
    return date.getFullYear() + '-' + ((date.getMonth() + 1) > 9 ? (date.getMonth() + 1) : ('0' + (date.getMonth() + 1))) + '-' + (date.getDate() > 9 ? date.getDate() : ('0' + date.getDate()));
}


exports.formatTime = function (data) {
    var date = new Date(data);
    return date.getFullYear() + '-' + ((date.getMonth() + 1) > 9 ? (date.getMonth() + 1) : ('0' + (date.getMonth() + 1))) + '-' +
        (date.getDate() > 9 ? date.getDate() : ('0' + date.getDate())) + ' ' +
        (date.getHours() > 9 ? date.getHours() : ('0' + date.getHours())) + ':' +
        (date.getMinutes() > 9 ? date.getMinutes() : ('0' + date.getMinutes())) + ':' +
        (date.getSeconds() > 9 ? date.getSeconds() : ('0' + date.getSeconds()));
}

/**
 * 获取屏幕宽高对象
 * @returns {*}
 */
exports.getWindowHeight = function () {
    return {
        h: wx.getSystemInfoSync().windowHeight,
        w: wx.getSystemInfoSync().windowWidth,
    };
}
exports.getScreen = function () {
  return {
    h: wx.getSystemInfoSync().windowHeight,
    w: wx.getSystemInfoSync().windowWidth,
  };
}

/**
 *  取数字num的最小10倍数
 * @returns {{h: (*|string|number), w: (*|string)}}
 */
exports.getMin10 = function (num) {
    let t = num || 0;
    return (parseInt((t + '').slice(0, 1)) + 1) * Math.pow(10, (t + '').length - 1);
}
